const express = require('express'),
    db = require('../db'),
    router = express();

router.post('/', (req, res, next) => {
    let username = req.body.username;
    let password = req.body.password;
    db.User.find({ username: username }).exec(function (err, data) {
        console.log(data)
        if (data.length == 1 && password == data[0].password) {
            res.json({ code: "success", data: { user: username }, message: "登录成功！" });
        } else if (data[0].username != username) {
            res.json({ code: "error", message: "帐号不存在！" });
        } else {
            res.json({ code: "error", message: "帐号或密码错误！" });
        }
    })
})

module.exports = router;